

// [ 0 - 3]
const ParamMax = 3;
cc.Class({
    extends: cc.Component,

    properties: {
        blurMaterial:cc.Material,
        slider:cc.Slider,
    },

    // LIFE-CYCLE CALLBACKS:
    ctor(){
        this.sp_dst = null;
        this.curMaterial = null;

        this.blurParams = ParamMax/2;
    },


    initWithDstSprite(sp){
        this.sp_dst = sp;
        this.sp_dst.setMaterial(0,this.blurMaterial);
        this.curMaterial = this.sp_dst.getMaterial(0);

        this.slider.progress = this.valueToProgress(this.blurParams);
        this.curMaterial.setProperty('u_bluramount',this.blurParams);
    },

    onSliderChanged(){
        cc.log(`onSliderChanged called!`);
        let progress = this.slider.progress;
        this.blurParams = this.progressToValue(progress);
        this.curMaterial.setProperty('u_bluramount',this.blurParams);
    },

    progressToValue(progress){
        return progress * ParamMax;
    },

    valueToProgress(value){
        return value / ParamMax;
    }
});
